package edu.bu.cs673.superkids123.common.view;

import java.awt.BorderLayout;
import java.awt.LayoutManager;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

import edu.bu.cs673.superkids123.children.model.Theme;
import edu.bu.cs673.superkids123.children.model.resources.ChildrenResource;
import edu.bu.cs673.superkids123.children.model.resources.ChildrenResourceProvider;

public class MenuPanel extends JPanel {
	
	/**
	 * Silences a warning, otherwise unnecessary
	 */
	private static final long serialVersionUID = 1L;
	
	// Header
	JPanel headerPanel = new JPanel(new BorderLayout());
	private JButton backButton = new JButton("Back");
	private JLabel titleLabel = new JLabel("Title");
	private JButton avatarButton = new JButton("Avatar");
	
	// Body
	private TitledBorder titleBorder = BorderFactory.createTitledBorder("Titled Border");
	private JPanel contentPanel = new JPanel();
	private JScrollPane scrollPane;
	
	// Footer
	private JPanel footerPanel = new JPanel(new BorderLayout());
	private JButton parentsButton = new JButton("Parents");
	
	public MenuPanel() {
		
		this(new BorderLayout());
	}
	
	public MenuPanel(LayoutManager layout) {

		super(layout);
		
		ChildrenResourceProvider provider = ChildrenResourceProvider.getInstance();

		// Header
		backButton.setIcon(provider.getImage(ChildrenResource.imageIconBack));
		backButton.setFont(Theme.CHILD_FONT_SMALL);
		backButton.setVerticalTextPosition(JButton.BOTTOM);
		backButton.setHorizontalTextPosition(JButton.CENTER);
		backButton.setBorder(BorderFactory.createEmptyBorder());
		backButton.setContentAreaFilled(false);
		
		titleLabel.setFont(Theme.CHILD_FONT_LARGE);
		titleLabel.setHorizontalAlignment(SwingConstants.CENTER);

		avatarButton.setContentAreaFilled(false);
		
		headerPanel.add(backButton, BorderLayout.WEST);
		headerPanel.add(titleLabel, BorderLayout.CENTER);
		headerPanel.add(avatarButton, BorderLayout.EAST);

		// Body
		titleBorder.setTitleFont(Theme.CHILD_FONT_SMALL);
		
		scrollPane = new JScrollPane(contentPanel,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);		
		scrollPane.getVerticalScrollBar().setUnitIncrement(16);
		//childScrollPane.getVerticalScrollBar().addAdjustmentListener(
		//		new ScrollBarAction());
		scrollPane.setBorder(titleBorder);
		
		// Footer
		parentsButton.setIcon(provider.getImage(ChildrenResource.imageIconSettings));
		parentsButton.setVerticalTextPosition(JButton.BOTTOM);
		parentsButton.setHorizontalTextPosition(JButton.CENTER);
		parentsButton.setFont(Theme.CHILD_FONT_SMALL);
		parentsButton.setBorder(BorderFactory.createEmptyBorder());
		parentsButton.setContentAreaFilled(false);
		footerPanel.add(parentsButton, BorderLayout.EAST);

		// Add to layout
		this.add(headerPanel, BorderLayout.PAGE_START);		
		this.add(scrollPane, BorderLayout.CENTER);
		this.add(footerPanel, BorderLayout.PAGE_END);
	}

	public JPanel getHeaderPanel() {
		return headerPanel;
	}

	public JButton getBackButton() {
		return backButton;
	}

	public JLabel getTitleLabel() {
		return titleLabel;
	}

	public JButton getAvatarButton() {
		return avatarButton;
	}

	public TitledBorder getTitleBorder() {
		return titleBorder;
	}

	public JPanel getContentPanel() {
		return contentPanel;
	}

	public JScrollPane getScrollPane() {
		return scrollPane;
	}

	public JPanel getFooterPanel() {
		return footerPanel;
	}

	public JButton getParentsButton() {
		return parentsButton;
	}
}
